# Powershell profile
# Updated: 2020-08-17
# 
# Prerequisites
# posh-git (installed from PowershellGallery / Scoop)
# PSReadLine (installed from PowershellGallery)
# PSReadLineHistory (installed from PowershellGallery)
# scoop-completion (installed from Scoop)
# 
# *colorls (ruby package)
# Scoop
# concfg (installed from Scoop)
# pshazz (installed from Scoop)

# change code page to UTF-8
# this isn't compatible with java
chcp 65001

try { $null = gcm pshazz -ea stop; pshazz init 'dorin' } catch { }
# try { $null = Get-Command concfg -ea stop; concfg tokencolor -n disable } catch { }

# =====**************=====
# put your settings here
# =====**************=====

# =====IMPORT=====

# Posh-Git: https://github.com/dahlbyk/posh-git
Import-Module posh-git

# scoop_completion: https://github.com/Moeologist/scoop-completion
Import-Module scoop-completion
# scoop config alias @{}

# PSReadLineHistory: https://github.com/realslacker/PSReadlineHistory
#Optimize-PSReadlineHistory -MaximumCommandCount 500 -Passthru
If (Test-Path Alias:\history) { Remove-Item Alias:history }
If (Test-Path Alias:\h) { Remove-Item Alias:h }
Set-Alias -Name history -Value Get-PSReadlineHistory
Set-Alias -Name h -Value Get-PSReadlineHistory
If (Test-Path Alias:\r) { Remove-Item Alias:r }
Set-Alias -Name r -Value Invoke-PSReadlineHistory

# =====FUNCTION=====

function .. { Set-Location .. }

# This requires z.ps: https://github.com/JannesMeyer/z.ps
# which has been include in pshazz
function cd- { z -s recent | Select-Object -Property Path -First 1 | Set-Location }

function la { Get-ChildItem -Force }

function Edit-PSProfile { echo "Edit Powershell profiles with notepad(3) ..."; notepad $PROFILE }

function Edit-Hosts {
    echo "Edit hosts with notepad(3) ...";
    echo "Using hosts manager is recommended (use scoop to search)";
    sudo notepad C:\Windows\System32\drivers\etc\hosts;
}

function gst {
    echo "git status"
    git status
}

function gba {
    echo "git branch -a"
    git branch -a
}

function gbr {
    echo "git branch -r"
    git branch -r
}

function gbvv {
    echo "git branch -vv"
    git branch -vv
}

function glola {
  git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --all
}

# =====ALIAS=====

If (Test-Path Alias:curl) { Remove-Item Alias:curl }
#If (Test-Path Alias:curl) { Remove-Item Alias:curl }
Set-Alias -Name reboot -Value Restart-Computer
Set-Alias -Name npd -Value notepad
Set-Alias -Name open -Value Invoke-Item

# =====VARIABLES & ENV=====

$env:PYTHONIOENCODING="utf-8"
$env:GIT_SSH_COMMAND='"C:\Program Files\Scoop\apps\win32-openssh\current\ssh.exe" -T'
$env:PYTHON_BUILD_MIRROR_URL="http://npm.taobao.org/mirrors/python/"

# =====SETTINGS=====

# Enable bash style completion without using Emacs mode
# Set-PSReadLineKeyHandler -Key Tab -Function Complete

# Enable "Menu" completion (somewhat like Intellisense, select completion with arrows) via Ctrl+Space
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete

# Output some tips
# function Prompt-Tips {
#     if ($args.Count -gt 0)
#     {
#         echo "$([char]27)[46m$args$([char]27)[0m"
#     }
# }

# Prompt-Tips "  - You need manually change code page to utf-8 with command ``chcp 65001``.`n"
